package com.my.cd.factory.abstractFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import com.my.cd.factory.pizza.Pizza;

/**
 * 抽象工厂的使用类：披萨订单类
 */
@SuppressWarnings("all")
public class OrderPizza {

    private AbstractFactory factory;

    public OrderPizza(AbstractFactory factory) {
        setFactory(factory);
    }

    public void setFactory(AbstractFactory mFactory) {
        Pizza pizza;
        String ordertype;
        this.factory = mFactory;
        do {
            ordertype = getType();
            pizza = mFactory.createPizza(ordertype);
            if (pizza != null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }
        } while (true);
    }

    private String getType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            return strin.readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }

}
